package com.ysm.smfu.food.share;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.widget.Toast;

import com.umeng.socialize.ShareAction;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;
import com.umeng.socialize.shareboard.ShareBoardConfig;
import com.umeng.socialize.shareboard.SnsPlatform;
import com.umeng.socialize.utils.ShareBoardlistener;
import com.ysm.smfu.R;
import com.ysm.smfu.contans.Defaultcontent;

/**
 * Created by Administrator on 2017/4/11.
 */
public class ShareBuild {
    public static ShareAction getShareAction(final Activity activity, final CustomShareListener customShareListener) {
        /*增加自定义按钮的分享面板*/
        ShareAction shareAction = new ShareAction(activity).setDisplayList(
                SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,
                SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE,
                SHARE_MEDIA.SMS)
//                .addButton("umeng_sharebutton_copy", "umeng_sharebutton_copy", "umeng_socialize_copy", "umeng_socialize_copy")
                .addButton("umeng_sharebutton_copyurl", "umeng_sharebutton_copyurl", "umeng_socialize_copyurl", "umeng_socialize_copyurl")
                .setShareboardclickCallback(new ShareBoardlistener() {
                    @Override
                    public void onclick(SnsPlatform snsPlatform, SHARE_MEDIA share_media) {
                        if (snsPlatform.mShowWord.equals("umeng_sharebutton_copy")) {
                            Toast.makeText(activity, "复制文本按钮", Toast.LENGTH_LONG).show();
                        } else if (snsPlatform.mShowWord.equals("umeng_sharebutton_copyurl")) {
                            //获取剪贴板管理器：
                            ClipboardManager cm = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
                            // 创建普通字符型ClipData
                            ClipData mClipData = ClipData.newPlainText("Label", Defaultcontent.url);
                            // 将ClipData内容放到系统剪贴板里。
                            cm.setPrimaryClip(mClipData);
                            Toast.makeText(activity, "已复制到剪贴板", Toast.LENGTH_LONG).show();
                        } else {
                            UMWeb web = new UMWeb(Defaultcontent.url);//分享的链接地址
                            web.setTitle("来自云数贸");
                            web.setDescription("来自云数贸的商家");
                            web.setThumb(new UMImage(activity, R.drawable.logo));
                            new ShareAction(activity).withMedia(web)
                                    .setPlatform(share_media)
                                    .setCallback(customShareListener)
                                    .share();
                        }
                    }
                });
        return shareAction;
    }

    public static ShareBoardConfig getShareBoardConfig() {
        ShareBoardConfig config = new ShareBoardConfig();
        config.setMenuItemBackgroundShape(ShareBoardConfig.BG_SHAPE_NONE);
        config.setIndicatorVisibility(false);
        config.setTitleVisibility(false);
        config.setCancelButtonText("取消");
        return config;
    }
}
